<%@ page import="java.util.List" %>
<%@ page import="com.baidu.Student" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>分页显示学生列表</title>
</head>
<body>

<h2>学生列表</h2>

<table border="1">
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>年龄</th>
    </tr>
    </thead>
    <tbody>
    <%
        int currentPage = (int) request.getAttribute("currentPage");
        int totalPages = (int) request.getAttribute("totalPages");
        List<Student> studentList = (List) request.getAttribute("studentList");
    %>
    <%
        for (int i = 0; i < studentList.size(); i++) {
    %>
    <tr>
        <td><%=studentList.get(i).getId() %></td>
        <td><%=studentList.get(i).getName() %></td>
        <td><%=studentList.get(i).getAge() %></td>
    </tr>
    <%
        }
    %>
<%--    <c:forEach var="student" items="${studentList}">--%>

<%--        <tr>--%>
<%--            <td>${student.id}</td>--%>
<%--            <td>${student.name}</td>--%>
<%--            <td>${student.age}</td>--%>
<%--        </tr>--%>
<%--    </c:forEach>--%>
    </tbody>
</table>

<p>
    第<%=currentPage %> 页 / 共 <%=totalPages%> 页

<% int shang = currentPage-1;
   if (shang ==0 ){
       shang=1;
   }
   int xia = currentPage+1;
   if (xia == totalPages+1 ){
       xia = totalPages;
   }
%>
    <a href="/StudentServlet?page=<%=shang%>">上一页</a>
    <a href="/StudentServlet?page=<%=xia%>">下一页</a>
<%--    <a href="?page=${currentPage + 1}">下一页</a>--%>
<%--    <c:if test="${currentPage > 1}">--%>
<%--        <a href="?page=${currentPage - 1}">上一页</a>--%>
<%--    </c:if>--%>
<%--    <c:if test="${currentPage < totalPages}">--%>
<%--        --%>
<%--    </c:if>--%>
</p>

</body>
</html>
</body>

</html>
